package com.qqtech.qquan.sys.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.model.PageKit;
import com.qqtech.core.frame.model.PageOrder;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.sys.dao.SysAreaDao;
import com.qqtech.qquan.sys.model.SysArea;
import com.qqtech.qquan.sys.model.SysAreaQuery;
import com.qqtech.qquan.sys.model.SysAreaVo;

@Service
public class SysAreaServiceImpl extends BaseServiceImpl<SysArea> implements SysAreaService {
	public static final Logger log = LoggerFactory.getLogger(SysAreaServiceImpl.class);

	@Resource
	private SysAreaDao sysAreaDao;

	@Override
	protected BaseDao<SysArea> getBaseDao() {
		return sysAreaDao;
	}

	@Override
	public List<SysAreaVo> findAreaByParent(Integer parentId) {
		Pageable pageKit = new PageKit(1, Integer.MAX_VALUE, new PageOrder(Direction.ASC, "id"));
		SysAreaQuery q = new SysAreaQuery();
		q.setParentId(parentId);
		if (null == parentId) {
			q.setLevel(1);
		}
		return sysAreaDao.queryList(q, pageKit);
	}

	@Override
	public SysAreaVo getParentArea(Integer id) {
		SysAreaVo sysAreaVo = sysAreaDao.getById(id);
		if (null != sysAreaVo.getParentId()) {
			sysAreaVo = sysAreaDao.getById(sysAreaVo.getParentId());
		}
		return sysAreaVo;
	}

}